package com.gym.openapi.common;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.ToString;

/**
 * @author ming
 * 2021/11/23
 * description:统一返回数据类型
 */
@Data
@ToString
@AllArgsConstructor
@NoArgsConstructor
public class ResponseResult<T> {

    private boolean status;
    private String msg;
    private T t;

    /**
     * @author:ming
     * @Date: 2021/11/23
     * @description:成功响应的信息
     * 一般配合枚举常量使用
     * 分四种情况，1.只需知道成功与否，不需要信息
     * 2.什么成功了 3.成功后只需要数据  4.需要成功信息和数据
     */
    public static ResponseResult getSuccess() {
        return new ResponseResult(ResponseCode.SUCCESS.getStatus(), ResponseCode.SUCCESS.getCommon(), null);
    }

    public static ResponseResult getSuccess(String msg) {
        return new ResponseResult(true, msg, null);
    }

    public static <T> ResponseResult getSuccess(T t) {
        return new ResponseResult(true, null, t);
    }

    public static <T> ResponseResult getSuccess(String msg, T t) {
        return new ResponseResult(true, msg, t);
    }


    /**
     *@author:ming
     *@Date: 2021/11/23
     *@description:失败响应
     */
    public static ResponseResult getFail() {
        return new ResponseResult(false, null, null);
    }

    public static ResponseResult getFail(String msg) {
        return new ResponseResult(false, msg, null);
    }

    public static <T> ResponseResult getFail(T t) {
        return new ResponseResult(false, null, t);
    }

    public static <T> ResponseResult getFail(String msg, T t) {
        return new ResponseResult(false, msg, t);
    }

}
